package com.upc.cajabancos.dao;

import java.sql.CallableStatement;
import java.sql.Connection;

import oracle.jdbc.driver.OracleTypes;

import com.upc.cajabancos.model.DetalleDocumentoPago;
import com.upc.cajabancos.util.DataAccessObjetc;

public class DetalleDocumentoPagoDAO {
	
	private Connection connection = null;
	
	public DetalleDocumentoPagoDAO(Connection connection){
		this.connection = connection;
	}
	
	public void registrar(String numero, DetalleDocumentoPago detalle) throws Exception{
		
		CallableStatement cst= null;
		
		try{
			
			cst= connection.prepareCall(DataAccessObjetc.buildProcedureCall("REGISTRAR_DETDOCUMENTOPAGO",7));
			cst.setString(1, numero);
			cst.setInt(2, detalle.getItem());
			if(detalle.getDocumentoAsociado() == null){
				cst.setNull(3, OracleTypes.NULL);
			}
			else{
				cst.setString(3, detalle.getDocumentoAsociado().getCodigo());
			}
			if(detalle.getDetalleOrdenPago()==null){
				cst.setNull(4, OracleTypes.NULL);
			}
			else{
				cst.setInt(4, detalle.getDetalleOrdenPago().getItem());
			}
			cst.setString(5, detalle.getMotivo());
			cst.setString(6, detalle.getEstado());
			cst.setDouble(7, detalle.getMonto());
			
			cst.execute();
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		finally{
			DataAccessObjetc.close(null, cst, null);
		}
	}

}
